package com.kx.game.center.common;

import com.kx.game.center.common.enums.IndexedEnum;
import com.kx.game.center.redis.RedisConstant;
import com.kx.game.center.utils.EnumUtil;

import java.util.List;

public enum UserEnum implements IndexedEnum {
    OnLine(1, "玩家在线信息", RedisConstant.SERVER_LOGIN),
    UserInfo(2, "玩家基本信息", RedisConstant.USER_INFO),
    FriendCode(3, "好友码对应UserId", RedisConstant.FRIEND_CODE),;

    private final int index;

    private String param;

    private String type;

    UserEnum(int index, String param, String type) {
        this.index = index;
        this.param = param;
        this.type = type;
    }

    /**
     * 按索引顺序存放的枚举数组
     */
    private static final List<UserEnum> indexes = IndexedEnumUtil
            .toIndexes(UserEnum.values());

    public static UserEnum indexOf(final int index) {
        return EnumUtil.valueOf(indexes, index);
    }

    public static UserEnum getMaxPlatformType() {
        for (int i = indexes.size() - 1; i > 0; i--) {
            if (indexes.get(i) != null)
                return indexes.get(i);
        }
        return null;
    }

    @Override
    public int getIndex() {
        return index;
    }

    public String getParam() {
        return param;
    }

    public void setParam(String param) {
        this.param = param;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public static List<UserEnum> getIndexes() {
        return indexes;
    }
}
